package cn.itcast.mq.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author Ang
 */
@Slf4j
@Component
public class SpringRabbitListener {

//    @RabbitListener(queues = "simple.queue")
//    public void listenSimpleQueue(String msg) {
//        System.out.println("消费者接收到simple.queue的消息：【" + msg + "】");
//    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "dl.ttl.queue", durable = "true"),
            exchange = @Exchange(name = "dl.ttl.exchange"),
            key = "dl"
    ))
    public void listenDlQueue(String msg) {
        log.info("消费者接收到dl.ttl.queue的消息：{}", msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(
                    name = "delay.queue",
                    durable = "true"
            ),
            exchange = @Exchange(
                    name = "delay.direct",
                    delayed = "true"
            ),
            key = "delay"
    ))
    public void listenDelayQueue(String msg) {
        log.info("接收到delay.queue的延迟消息：{}", msg);
    }

    @RabbitListener(queuesToDeclare = @Queue(
                    name = "delay.queue",
                    durable = "true",
                    arguments = @Argument(
                            name = "x-queue-mode",
                            value = "lazy"
                    )
            )
    )
    public void listenLazyQueue(String msg) {
        log.info("消费者接收到lazy.queue的消息：{}", msg);
    }
}
